package com.miku.blog.controller;

import com.miku.blog.annotation.SystemLog;
import com.miku.blog.domain.Comment;
import com.miku.blog.domain.pojo.ResponseResult;
import com.miku.blog.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author shkstart
 * @create ${}YEAR-06-08 12:38
 */
@Api(tags = "Blog[评论]")
@RestController
public class CommentController {

    @Autowired
    private CommentService commentService;


    @SystemLog(notes = "获取评论列表{前台博客系统}")
    @ApiOperation(value = "获取评论列表接口",notes = "根据文章ID 获取评论列表及相关数据 {二级列表} ，只获取通过审核的评论")
    @GetMapping("/comments")
    public ResponseResult getComments(@RequestParam("current") Integer current,
                                      @RequestParam("type") Integer type,
                                      @RequestParam(value = "articleId",required = false) Integer articleId)
    {
        return commentService.getComments(current,type,articleId);
    }



    @SystemLog(notes = "获取子评论列表{前台博客系统}")
    @ApiOperation(value = "获取子评论列表接口",notes = "根据评论ID 获取其对应的子评论列表，分页进行展示 {只获取通过审核的评论}")
    @GetMapping("/comments/replies/{commentId}")
    public ResponseResult getChildrenComments(@PathVariable("commentId") Integer commentId,
                                              @RequestParam("current") Integer current,
                                              @RequestParam("size") Integer size)
    {
        return commentService.getChildrenComments(commentId,current,size);
    }



    @SystemLog(notes = "添加评论{前台博客系统}")
    @ApiOperation(value = "添加评论接口",notes = "添加评论数据")
    @PostMapping("/comments")
    public ResponseResult addComment(@RequestBody Comment comment)
    {
        return  commentService.addComment(comment);
    }


}
